Saturday, January 06, 2018

The advantage and disadvantage of using a debugger...

Before you read on, watch this video carefully and see if you notice a pitfall...


Advantage: it helps one locate where something breaks quite quickly...

Disadvantage: it is so fast that it's very easy to skip over the root of why something broke and "just patch things up"...

In the video, the surface problem (where the error manifested) is the concatenation of two strings where an addition of two numbers was expected, but the actual problem (why) is not String + String vs. Number + Number but rather a bit deeper, it is in the way the values are accessed, you call getNumberX(..) and get a string rather than a number, and in this particular case fixing the root problem (i.e. returning a Number) will eliminate a whole class of potential errors while the solution given in the vid will only "mask" the error and lead to code bloat that is very hard to clear up later.

To reiterate, the debugger helps one locate the breakage, and maybe patch a particular case (wrong operation type in the vid) but it does not replace the skill to find/see the actual root of the breakage, the actual bug (here "getNumber returns String" name/return mismatch) and fix it.